home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Unsupported Libraries / Error_Lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  2.8 KB  |  123 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        Error_Lib.c                                                  **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:                                                               **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1994 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  **     Change Log:                                                             **
  14.  **                                                                          **
  15.  **                                                                          **
  16.  *****************************************************************************/
  17. #include <stdio.h>
  18.  
  19. #include "QD3D.h"
  20. #include "QD3DErrors.h"
  21.  
  22. #include "Error_Lib.h"
  23. #include "Error_MesgLib.h"
  24.  
  25. FILE *gErrorFile = NULL;
  26.  
  27. static void    ErrorHandler(
  28.     TQ3Error     firstError,
  29.     TQ3Error        lastError,
  30.     long        reference);
  31.     
  32. static void    WarningHandler(
  33.     TQ3Warning     firstWarning,
  34.     TQ3Warning     lastWarning,
  35.     long        reference);
  36.     
  37. static void    NoticeHandler(
  38.     TQ3Notice     firstNotice,
  39.     TQ3Notice     lastNotice,
  40.     long        reference);
  41.  
  42. void InstallDefaultErrorHandler(
  43.     void)
  44. {
  45.     if (gErrorFile == NULL)
  46.         gErrorFile = fopen("error.output","w+");
  47.         
  48.     Q3Error_Register(ErrorHandler, (long) gErrorFile);
  49. }
  50.  
  51.  
  52. void InstallDefaultWarningHandler(
  53.     void)
  54. {
  55.     if (gErrorFile == NULL)
  56.         gErrorFile = fopen("error.output","w+");
  57.         
  58.     Q3Warning_Register(WarningHandler, (long) gErrorFile);
  59. }
  60.  
  61.  
  62. void InstallDefaultNoticeHandler(
  63.     void)
  64. {
  65.     if (gErrorFile == NULL)
  66.         gErrorFile = fopen("error.output","w+");
  67.         
  68.     Q3Notice_Register(NoticeHandler, (long) gErrorFile);
  69. }
  70.  
  71. static void ErrorHandler(
  72.     TQ3Error     firstError,
  73.     TQ3Error     lastError,
  74.     long        reference)
  75. {
  76.     char buf[512];
  77.     TQ3Error    dummyError;
  78.     
  79.     sprintf(buf, "First ERROR %d:%s\n", firstError, getErrorString(firstError));
  80.     if (lastError != kQ3ErrorNone)
  81.         sprintf(buf, "\tLast ERROR %d:%s\n", lastError, getErrorString(lastError));
  82.  
  83.     fputs(buf,stdout);
  84.     if (reference != 0)
  85.         fputs(buf, (FILE *) reference);
  86.     
  87.     /* This clears the sticky error */
  88.     (void) Q3Error_Get(&dummyError);
  89. }
  90.  
  91.  
  92. static void WarningHandler(
  93.     TQ3Warning     firstWarning,
  94.     TQ3Warning     lastWarning,
  95.     long        reference)
  96. {
  97.     char buf[512];
  98.     
  99.     sprintf(buf, "First WARNING %d:%s\n", firstWarning, getWarningString(firstWarning));
  100.     if (lastWarning != kQ3WarningNone)
  101.         sprintf(buf, "\tLast WARNING %d:%s\n", lastWarning, getWarningString(lastWarning));
  102.  
  103.     fputs(buf,stdout);
  104.     if (reference != 0)
  105.         fputs(buf, (FILE *) reference);
  106. }
  107.  
  108. static void NoticeHandler(
  109.     TQ3Notice     firstNotice,
  110.     TQ3Notice     lastNotice,
  111.     long        reference)
  112. {
  113.     char buf[512];
  114.     
  115.     sprintf(buf, "First NOTICE %d:%s\n", firstNotice, getNoticeString(firstNotice));
  116.     if (lastNotice != kQ3NoticeNone)
  117.         sprintf(buf, "\tLast NOTICE %d:%s\n", lastNotice, getNoticeString(lastNotice));
  118.  
  119.     fputs(buf,stdout);
  120.     if (reference != 0)
  121.         fputs(buf, (FILE *) reference);
  122. }
  123.